package com.mazaiting.mybatisplus.config;

import com.mazaiting.mybatisplus.encrypt.IEncryptor;

import java.util.List;
import java.util.Objects;

/**
 * MybatisCryptoConfig配置类
 *
 * @author danghailiang
 */
public class MybatisCryptoConfig {
    /**
     * mybatis @Param 注解下需要加解密的参数 key 前缀
     */
    private List<String> mappedKeyPrefixes;
    /**
     * 快速失败
     */
    private boolean failFast;
    /**
     * 默认签名
     */
    private String key;
    /**
     * 默认加密处理器
     */
    private Class<? extends IEncryptor> encryptor;

    public MybatisCryptoConfig(List<String> mappedKeyPrefixes, boolean failFast, String key, Class<? extends IEncryptor> encryptor) {
        this.mappedKeyPrefixes = mappedKeyPrefixes;
        this.failFast = failFast;
        this.key = key;
        this.encryptor = encryptor;
        afterPropertiesSet();
    }

    /**
     * 判断配置文件传入的类是否是kong或者是IEncryptor接口
     */
    private void afterPropertiesSet() {
        if (Objects.equals(encryptor, IEncryptor.class)) {
            throw new IllegalArgumentException("encryptor must be not null or IEncryptor");
        }
    }

    public void setMappedKeyPrefixes(List<String> mappedKeyPrefixes) {
        this.mappedKeyPrefixes = mappedKeyPrefixes;
    }

    public void setFailFast(boolean failFast) {
        this.failFast = failFast;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public void setEncryptor(Class<? extends IEncryptor> encryptor) {
        this.encryptor = encryptor;
    }

    public List<String> getMappedKeyPrefixes() {
        return mappedKeyPrefixes;
    }

    public boolean isFailFast() {
        return failFast;
    }

    public String getKey() {
        return key;
    }

    public Class<? extends IEncryptor> getEncryptor() {
        return encryptor;
    }
}
